package com.bytebuffer;

import java.util.Iterator;

import io.netty.buffer.ByteBuf;
import io.netty.buffer.CompositeByteBuf;
import io.netty.buffer.Unpooled;

/**将多个缓冲区显示为一个合并缓冲区的虚拟缓冲区。建议使用{ByteBufAllocator#compositeBuffer()}或{unpooling #wrappedBuffer(ByteBuf…)}，而不是显式地调用构造函数。
 * @author Ziroom
 *
 */
public class CompositeByteBufDemo {

	public static void main(String[] args) {
		CompositeByteBuf compositeByteBuf = Unpooled.compositeBuffer();

		ByteBuf heapBuf = Unpooled.buffer(10);
		ByteBuf directBuf = Unpooled.directBuffer(0);

		compositeByteBuf.addComponents(heapBuf, directBuf);
		compositeByteBuf.removeComponent(0);

		Iterator<ByteBuf> iter = compositeByteBuf.iterator();
		while(iter.hasNext()) {
			System.out.println(iter.next());
		}
	}

}
